package com.lagou.edu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@Controller
@RequestMapping("/user")
public class UserController {

    @RequestMapping("/login")
    public void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        //request.setCharacterEncoding("utf-8");
        String username = new String(request.getParameter("username").getBytes("ISO-8859-1"),"utf-8");
        String password = request.getParameter("password");
        System.out.println(username + "," + password);
        System.out.println("method UserController findAll");
        if ("admin".equals(username) && "admin".equals(password)){
            request.getSession().setAttribute("username", username);
            request.getRequestDispatcher("/resume.jsp").forward(request, response);
        }else {
            request.getSession().setAttribute("state", -1);
            request.getSession().setAttribute("msg", "用户名或密码不正确");
            request.getRequestDispatcher("/login.jsp").forward(request, response);
        }
    }
}
